package util;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.TimeZone;

public class ParameterCheck {
	public static String checkNull(String p, String defaultNull) {
		if (null == p)
			return defaultNull;
		if ("".equals(p.trim()))
			return defaultNull;
		return p;
	}

	public static Object getObjectValue(Object o, Object defaultObj) {
		if (null == o)
			return defaultObj;
		else
			return o;
	}

	public static String stringDefault(String p) {
		if (null == p)
			return "";
		if ("".equals(p.trim()))
			return "";
		return p.trim();
	}

	public static int intDefault(String p) {
		if (null == p)
			return 0;
		if ("".equals(p.trim()))
			return 0;
		return Integer.valueOf(p);
	}

	public static String getTimeFormat(String time) {
		if (null == time)
			return time;
		SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm");
		format.setTimeZone(TimeZone.getTimeZone("GMT+8"));

		try {
			Date date = format.parse(time);
			time = format.format(date);
//			date = new Date();
//			String today = format.format(date).split(" ")[0] + " ";
//			time = time.replace(today, "");
		} catch (ParseException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			System.out.println("time:" + time);
		} catch (Exception e) {
			e.printStackTrace();
			System.out.println("time:" + time);
		}

		return time;
	}

	/**
	 * 有空值就返回true
	 * @return
	 */
	public static boolean isEmpty(String... str) {
		for (String s : str) {
			if (null == s || "".equals(s)) {
				return true;
			}
		}
		return false;
	}

	public static void main(String args[]) {
		System.out.println(getTimeFormat("2011-12-12 15:13:122"));
		System.out.println(getTimeFormat("2011-12-15 15:11:122"));
		System.out.println(getTimeFormat(null));
		//		String[] pinyinArray =  PinyinHelper.toHanyuPinyinStringArray('長');
		//		System.out.println(pinyinArray==null);
		//		System.out.println(pinyinArray[0]);
		//		for (int i=0;i<pinyinArray.length;i++)			
		//			System.out.println(pinyinArray[i]);

		System.out.println(PinYin.getPinyin("1"));
		String st1 = "abc";
		String st2 = "sklasdkl\"as\"\"klsf";
		System.out.println(MyJson.toJson(st1, st2));

	}
}
